"""
 -*- coding: utf-8-*-
 @File: page_login.py
 @Author: chen
 @time: 2023/12/03/ 10:13
"""
import os.path

from stage_L1.lim_project.page_po.businesses.page_base import BasePage
from stage_L1.lim_project.page_po.utils.mgt_logger import logger
from stage_L1.lim_project.page_po.utils.mgt_yaml import YamlMgt

cur_path = os.path.dirname(os.path.abspath(__file__))
login_file = os.path.join(cur_path, "./config/login_config.yaml")
login_data = YamlMgt.read(login_file)


class LoginPage(BasePage):
    """登录页面"""
    url = login_data.get("test_url")
    username = login_data.get("username")
    password = login_data.get("password")

    def login(self):
        _span_login = (self.BY.XPATH, r'//*[text()="> 点我登录"]')
        _input_username = (self.BY.ID, r'basic_username')
        _input_password = (self.BY.ID, r'basic_password')
        _btn_login = (self.BY.XPATH, r'//*[text()="登 录"]')
        logger.info(f"打开测试网址：{self.url}")
        self.do_get(self.url)
        logger.info(f"点击点我登录按钮")
        self.do_click(_span_login)
        logger.info(f"输入用户名")
        self.do_input(_input_username, self.username)
        logger.info(f"输入密码")
        self.do_input(_input_password, self.password)
        logger.info("点击登录按钮")
        self.do_click(_btn_login)
        from stage_L1.lim_project.page_po.businesses.page_home import HomePage
        logger.info("成功进入首页")
        return HomePage(self.driver)


if __name__ == '__main__':
    L0 = LoginPage()
    L0.login()
